package com.my.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import cn.hutool.json.JSONObject;
import com.my.R;
import com.my.adapter.entity.AskLeave;

import java.util.List;

public class AskLeaveAdapter extends ArrayAdapter<JSONObject> {

    private int resourceId;

    public AskLeaveAdapter(@NonNull Context context, int resource, @NonNull List<JSONObject> objects) {
        super(context, resource, objects);
        resourceId = resource;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        JSONObject leave = getItem(position);
        View view = LayoutInflater.from(getContext()).inflate(resourceId, null);
        ((TextView) view.findViewById(R.id.u_name)).setText(leave.getStr("sname"));
        ((TextView) view.findViewById(R.id.grade_class)).setText(leave.getStr("gname") + leave.getStr("cname"));
        ((TextView) view.findViewById(R.id.createTime)).setText(leave.getStr("createTime"));
        ((TextView) view.findViewById(R.id.status)).setText(leave.getInt("status") == 1 ? "待审核" : (leave.getInt("status") == 2 ? "通过" : "未通过"));
        return view;
    }
}
